home *** CD-ROM | disk | FTP | other *** search
- #include "work:romconf/includes.h"
- #include "work:romconf/doorheader.h"
- #include "struct.h"
- #define c1 ansi?"":""
- #define c2 ansi?"":""
- #define c3 ansi?"":""
- #define c4 ansi?"":""
- #define c5 ansi?"":""
- #define c6 ansi?"":""
- #define c7 ansi?"":""
- #define SM sendmessage
- #define PM prompt
- #define HK hotkey
- #define GU getuserstring
- #define BRIEF 1
-
- void DisplayMap(int x,int y);
- void GetCommands();
- void LoadMap();
- void ShowCharacters(int Num,int Option);
- char *GetTheDate();
- char Map[9][12];
- int x,y;
- int UserNum=-1;
- main(int argc,char *argv[])
- {
-
- Register(argv[1][0]-'0');
- x=y=0;
- if(!GetLogon()) { ShutDown(); end(); }
- LoadMap();
- GetCommands();
- }
-
- int GetLogon()
- {
- FILE *fi;
- char CMD[200];
- getuserstring(CMD,DT_NAME);
- int UserNum =0;
- int Slot = -1;
- strupr(CMD);
- InitStructures();
- fi=fopen("DOORS:DAND/User.dta","r+b");
- if(fi==NULL)
- {
- if(GetNewAccount())
- return(1); else return(0);
- }
-
- while(fread((APTR)&Player,sizeof(struct User),1,fi)!=NULL)
- {
-
- if(!strcmp(CMD,Player.UserName))
- {
- fclose(fi);
- return(1);
- }
- if(Player.Slot==-1) Slot=UserNum;
- UserNum +=1;
- }
- fclose(fi);
- InitStructures();
- Player.Slot= (Slot==-1?UserNum:Slot);
- if(GetNewAccount()) return(1); else return(0);
- }
-
- int GetNewAccount()
- {
- char CMD[200];
- FILE *fi;
- sprintf(CMD,"%sYou must be new to this Realm. Would you like to participate in",c6);
- SM(CMD,1);
- sprintf(CMD,"%sByteMaster's%s Dungeons ",c1,c6);
- SM(CMD,0);
- if(YesNo())
- {
- fi=fopen("DOORS:DAND/User.dta","r+b");
- if(fi==NULL)
- {
- fi=fopen("DOORS:DAND/User.dta","wb");
- }
- if(fseek(fi,(LONG)sizeof(struct User)*(LONG)Player.Slot,SEEK_SET))
- {
- fclose(fi); fi=fopen("DOORS:DAND/User.dta","ab");
- }
- fwrite((APTR)&Player,sizeof(struct User),1,fi);
- fclose(fi);
- GetUserData();
- return(1);
- }
- return(0);
- }
- void GetUserData()
- {
- char CMD[200];
- int i=0;
- while(1)
- {
- sprintf(CMD,"%sPlease enter an Alias >:",c4);
- PM(CMD,CMD,30);
- SM("Are you sure ",0); if(YesNo()) break;
- }
- strcpy(Player.Handle,CMD);
- SM("Now you must create 4 characters.",1);
- while(i<4)
- {
- sprintf(CMD,"%sCreating Character %s[%s%d%s]%s",c2,c6,c3,i+1,c6,"");
- SM(CMD,1);
- while(1)
- {
- sprintf(CMD,"%sPlease enter character name >:%s",c2,c4);
- PM(CMD,CMD,20);
- SM("Are you sure ",0); if(YesNo()) break;
- }
- strcpy(Player.Party[i].Leader);
- while(1)
- {
-
- sprintf(CMD,"%sPlease choose from the following classes:%s (%sMaybe more than 1%s)",c2,c3,c1,c3);
- SM(CMD,1);
- sprintf(CMD,"%s[%sF%s]ighter, [%sC%s]leric, [%sT%s]hief, [%sM%s]agicUser",c6,c3,c6,c3,c6,c3,c6,c3,c6);
- SM(CMD,1);
- HK(">:",CMD);
- strupr(CMD);
- if(CMD[0]!='F' && CMD[0]!='C' && CMD[0]!='T' && CMD[0]!='M')
- {
- if(Player.Party[i].Class[0]!=' ' || Player.Party[i].Class[1]!=' ' ||
- Player.Party[i].Class[2]!=' ' || Player.Party[i].Class[3]!=' ') break;
- }
- else switch(CMD[0])
- {
- case 'F': Player.Party[i].Class[0]=(Player.Party[i].Class[0]=='F'?' ':'F'); break;
- case 'C': Player.Party[i].Class[1]=(Player.Party[i].Class[1]=='C'?' ':'C'); break;
- case 'T': Player.Party[i].Class[2]=(Player.Party[i].Class[2]=='T'?' ':'T'); break;
- case 'M': Player.Party[i].Class[3]=(Player.Party[i].Class[3]=='M'?' ':'M'); break;
- }
- sprintf(CMD,"Character %s is currently a",Player.Party[i].Leader);
- SM(CMD,1);
- if(Player.Party[i].Class[0]!=' ') SM("FIGHTER ",0);
- if(Player.Party[i].Class[1]!=' ') SM("CLERIC ",0);
- if(Player.Party[i].Class[2]!=' ') SM("THIEF ",0);
- if(Player.Party[i].Class[3]!=' ') SM("MAGIC USER ",0);
- SM("",1);
- }
- while(1)
- {
-
- sprintf(CMD,"%sPlease choose from the following races:",c2);
- SM(CMD,1);
- sprintf(CMD,"%s[%sH%s]uman, [%sE%s]lf, [%sD%s]warf",c6,c3,c6,c3,c6,c3,c6);
- SM(CMD,1);
- HK(">:",CMD);
- strupr(CMD);
- if(CMD[0]!='H' && CMD[0]!='E' && CMD[0]!='D')
- {
- if(Player.Party[i].Race[0]!='\0') break;
- }
- else switch(CMD[0])
- {
- case 'H': strcpy(Player.Party[i].Race,"Human"); break;
- case 'E': strcpy(Player.Party[i].Race,"Elf"); break;
- case 'D': strcpy(Player.Party[i].Race,"Dwarf"); break;
- }
- sprintf(CMD,"Character %s is currently a %s",Player.Party[i].Leader,Player.Party[i].Race);
- SM(CMD,1);
- }
-
- }
- int YesNo()
- {
- char CMD[20];
- sprintf(CMD,"%s[%sY%s/%sn%s] >:",c6,c2,c6,c1,c6);
- HK(CMD,CMD);
- strupr(CMD);
- if(CMD[0]=='N') { SM("No.",1);return(0);}
- SM("Yes.",1); return(0);
- }
-
- void LoadMap()
- {
- FILE *fi;
- int i=0;
- fi=fopen("DOORS:DAND/MAP.DAT","r");
- if(fi==NULL)
- {
- SM("Can't locate Map.",1);
- ShutDown(); end();
- }
- while(fgets((char *)Map[i],10,fi)!=NULL) i++;
- fclose(fi);
- }
-
- InitStructures()
- {
- int i=0;
- int j=0;
- while(i<8)
- {
- strcpy(Player.Party[i].Leader,"");
- strcpy(Player.Party[i].Race,"");
- Player.Party[i].HenchMen=0;
- Player.Party[i].HenchLevel=0;
- Player.Party[i].Class[0]=' ';
- Player.Party[i].Class[1]=' ';
- Player.Party[i].Class[2]=' ';
- Player.Party[i].Class[3]=' ';
- Player.Party[i].Class[4]=' ';
- Player.Party[i].Experience[0]=0L;
- Player.Party[i].Experience[1]=0L;
- Player.Party[i].Experience[2]=0L;
- Player.Party[i].Experience[3]=0L;
- Player.Party[i].Experience[4]=0L;
- Player.Party[i].Level[0]=0;
- Player.Party[i].Level[1]=0;
- Player.Party[i].Level[2]=0;
- Player.Party[i].Level[3]=0;
- Player.Party[i].Level[4]=0;
- j=0;
- while(j<60)
- {
- Player.Party[i].Equipment[j]=' '; j++;
- }
- Player.Party[i].Credits=0L;
- Player.Party[i].ArmorClass=9;
- Player.Party[i].MaxPoints=0;
- j=0; while(j<5)
- {
- Player.Party[i].Attributes[j]=0;
- Player.Party[i].MaxAttributes[j]=0;
- j++;
- }
- i++;
- }
- strcpy(Player.UserName,"");
- strcpy(Player.Handle,"");
- strcpy(Player.LastOn,"");
- Player.SlotNum=0;
- }
-
- void GetCommands()
- {
- char CMD[200];
- int x1,y1;
- int error=0;
- while(1)
- {
- ShowCharacters(-1,BRIEF);
- DisplayMap(x,y);
- do
- {
- HK("Please enter command [N,S,E,W,Q] >:",CMD);
- strupr(CMD);
- }while(CMD[0]!='N' && CMD[0]!='S' && CMD[0]!='E' && CMD[0]!='W' &&
- CMD[0]!='Q');
- switch(CMD[0])
- {
- case 'N': SM("North.",1); x1=x;y1=y;
- y1 -=1;
- if(y1<0) { SM("Can't go that direction.",1); break; }
- if(Map[y1][x1]=='0')
- { SM("Ouch!",1); break; }
- x=x1;y=y1;
- break;
- case 'S': SM("South.",1); x1=x;y1=y;
- y1 +=1;
- if(y1>7) { SM("Can't go that direction.",1); break; }
- if(Map[y1][x1]=='0')
- { SM("Ouch!",1); break; }
- x=x1;y=y1;
- break;
- case 'E': SM("East.",1); x1=x;y1=y;
- x1 +=1;
- if(x1>7) { SM("Can't go that direction.",1); break; }
- if(Map[y1][x1]=='0')
- { SM("Ouch!",1); break; }
- x=x1;y=y1;
- break;
- case 'W': SM("West.",1); x1=x;y1=y;
- x1 -=1;
- if(x1<0) { SM("Can't go that direction.",1); break; }
- if(Map[y1][x1]=='0')
- { SM("Ouch!",1); break; }
- x=x1;y=y1;
- break;
- default:
- SM("Quit.",1); ShutDown(); end();
- }
- }
- }
- ShowCharacters(int Num,int Option)
- {
- FILE *fi;
-
- void DisplayMap(int x,int y)
- {
- char FileName[200];
- sprintf(FileName,"DOORS:DAND/ROOM%c",Map[y][x]);
- showgfile(FileName);
- }
- char *GetTheDate()
- {
- struct tm *tp;
- long t;
- int M,D,Y;
- char Date[9];
- char Day[4],Month[5],Year[3];
- char TheTime[27];
- time(&t);
- tp=localtime(&t);
- sprintf(TheTime,"%s",asctime(tp));
- sprintf(Day,"%.2s",&TheTime[8]);
- sprintf(Month,"%.3s",&TheTime[4]);
- sprintf(Year,"%.2s",&TheTime[22]);
- D=atoi(Day);
- Y=atoi(Year);
-
- if(!strncmp(Month,"Jan",3)) M=1;
- if(!strncmp(Month,"Feb",3)) M=2;
- if(!strncmp(Month,"Mar",3)) M=3;
- if(!strncmp(Month,"Apr",3)) M=4;
- if(!strncmp(Month,"May",3)) M=5;
- if(!strncmp(Month,"Jun",3)) M=6;
- if(!strncmp(Month,"Jul",3)) M=7;
- if(!strncmp(Month,"Aug",3)) M=8;
- if(!strncmp(Month,"Sep",3)) M=9;
- if(!strncmp(Month,"Oct",3)) M=10;
- if(!strncmp(Month,"Nov",3)) M=11;
- if(!strncmp(Month,"Dec",3)) M=12;
- sprintf(Date,"%02d-%02d-%02d",M,D,Y);
- return(Date);
- }
- char *GetDiff(char *Date1,char *Date2)
- {
- char D1[9],D2[9];
- int Month1,Day1,Year1;
- int Month2,Day2,Year2;
- int Total;
- strcpy(D1,Date1); strcpy(D2,Date2);
- if(D1[0]=='\0') return(5);
- Month2=atoi(D2);
- Day2=atoi(&D2[2]);
- Year2=atoi(&D2[5]);
- Month1=atoi(D1);
- Day1=atoi(&D1[2]);
- Year1=atoi(&D1[5]);
-
- if(Day2<Day1) Total=31-Day1+Day2;
- else Total=Day2-Day1;
- if(Month2<Month1) Total +=(12-Month1+Month2)*30;
- else if(Month2>Month1) Total +=(Month2-Month1)*30;
- return(Total);
- }
-